package edu.xust.controller;

import com.alibaba.fastjson.JSON;
import edu.xust.pojo.EquipBean;
import edu.xust.pojo.RoleBean;
import edu.xust.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.SessionScope;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class RoleController {
    RoleBean roleBean;
    @Autowired
    private RoleService roleService;//按类型注入
    //创建角色
    @RequestMapping(value = "/create",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String createRole(HttpSession httpSession){
        roleService.addRole(roleBean);
        httpSession.setAttribute("role",roleBean);
        return null;
    }

    //获取创建角色信息
    @RequestMapping(value = "/get",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String getRole(String username,String sex,String occupation){
        RoleBean findRole = roleService.findRole();
        if (findRole !=null )
            return "NO";
        roleBean = roleService.SelectRole(username, sex, occupation);
        String s = JSON.toJSONString(roleBean);//把对象转换为JSON字符串格式
        return s;
    }

    //获取角色信息
    @RequestMapping(value = "/getinf",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String getRoleInf(){
        roleBean = roleService.findRole();
        System.out.println(roleBean);
        String s = JSON.toJSONString(roleBean);//把对象转换为JSON字符串格式
        return s;
    }

    //获取装备信息
    @RequestMapping(value = "/geteqinf",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String getEquipInf(){
        List<EquipBean> list = roleService.findEqu();
        String s = JSON.toJSONString(list);//把对象转换为JSON字符串格式
        return s;
    }
}
